#include <string.h>
#include "cmd.h"
#include <stdlib.h>

void InitDisplayMsg(UBYTE *BlackImage){
	EPD_2IN9_Init(EPD_2IN9_FULL);
  Paint_SelectImage(BlackImage);
  Paint_Clear(WHITE);
	Paint_DrawString_EN(5, 0, "Ipaddr: ", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(25, 20, "000.000.000.000", &Font24, WHITE, BLACK);
	Paint_DrawString_EN(5, 50, "CPU Temp: 000~C", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(190, 50, "Use:000%", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(5, 70, "MEM Use: 0000/0000MB 000%", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(5, 90, "SSD: 0000/0000GB 000%  ", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(5, 105, "Disk: 0000/0000GB 000%  ", &Font16, WHITE, BLACK);
	
	EPD_2IN9_Display(BlackImage);
}

void ClearDisplayMsg(UBYTE *BlackImage){
	EPD_2IN9_Init(EPD_2IN9_FULL);
  Paint_SelectImage(BlackImage);
  Paint_Clear(WHITE);
	Paint_DrawString_EN(5, 0, "Ipaddr: ", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(25, 20, "0.0.0.0", &Font24, WHITE, BLACK);
	Paint_DrawString_EN(5, 50, "CPU Temp:   0~C", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(190, 50, "Use:  0%", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(5, 70, "MEM Use:    0/0   MB   0%", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(5, 90, "SSD:    0/0   GB   0%  ", &Font16, WHITE, BLACK);
	Paint_DrawString_EN(5, 105, "Disk:    0/0   GB   0%  ", &Font16, WHITE, BLACK);
	
	EPD_2IN9_Display(BlackImage);
}

void UpdateIp(UBYTE *BlackImage,char * Ipaddr,uint8_t addr_len){
	 
    char addr[addr_len];
	  int i;
	  for(i = 0; i <addr_len; i++){
		   addr[i] = Ipaddr[i];
		}
	  EPD_2IN9_Init(EPD_2IN9_PART);
    Paint_SelectImage(BlackImage);
   	Paint_ClearWindows(25, 20, 25 + Font24.Width * 15, 20 + Font24.Height, WHITE);//Ipaddr
    Paint_DrawString_EN(25, 20, addr, &Font24, WHITE, BLACK);//
	  EPD_2IN9_Display(BlackImage);
}
void UpdateCpuInfo(UBYTE *BlackImage,CpuInfo * cpuinfo){
	char temp[3] = {' ',' ',' '};
	char use[3] = {' ',' ',' '};
	EPD_2IN9_Init(EPD_2IN9_PART);
  Paint_SelectImage(BlackImage);
	if(cpuinfo->temp < 100){
		   temp[1] = cpuinfo->temp/10 + 0x30;
		   temp[2] = cpuinfo->temp%10 + 0x30;
	}
	else{
	     sprintf(temp,"%d",cpuinfo->temp);
	}
	if(cpuinfo->use < 100){
	    use[1] = cpuinfo->use/10 + 0x30;
		  use[2] = cpuinfo->use%10 + 0x30;
	}
	else{
		sprintf(use,"%d",cpuinfo->use);
	}
	Paint_ClearWindows(5+Font16.Width*10, 50, 5+Font16.Width*10+Font16.Width*3, 50 + Font16.Height, WHITE); //cputemp
  Paint_DrawString_EN(5+Font16.Width*10, 50, temp, &Font16, WHITE, BLACK);
	
	Paint_ClearWindows(190+Font16.Width*4, 50, 190+Font16.Width*4+Font16.Width*3, 50 + Font16.Height, WHITE); //CPU USE
  Paint_DrawString_EN(190+Font16.Width*4, 50, use, &Font16, WHITE, BLACK);
	EPD_2IN9_Display(BlackImage);
	
}
void UpdateMemInfo(UBYTE *BlackImage,MemInfo * meminfo){
    char use[5];
	  char total[5];
	  char use_percent[4];
	  if(meminfo->total < 1000){
		    //total[0] = ' ';
			  total[0] = meminfo->total / 100%10 + 0x30;
			  total[1] = meminfo->total / 10%10 + 0x30;
			  total[2] = meminfo->total %10 + 0x30;
			  total[3] = '\0';
		}
		else{
		    sprintf(total,"%d",meminfo->total);
		}
		if(meminfo->use < 1000){
		    use[0] = ' ';
			  use[1] = meminfo->use / 100%10 + 0x30;
			  use[2] = meminfo->use / 10%10 + 0x30;
			  use[3] = meminfo->use %10 + 0x30;
			  use[4] = '\0';
		}
		else{
		    sprintf(use,"%d",meminfo->use);
		}
		
		if(meminfo->use_percent < 100){
		    use_percent[0] = ' ';
			  use_percent[1] = meminfo->use_percent / 10%10 + 0x30;
			  use_percent[2] = meminfo->use_percent %10 + 0x30;
		    use_percent[3] = '\0';
		}
		else{
		    sprintf(use_percent,"%d",meminfo->use_percent);
		}
		EPD_2IN9_Init(EPD_2IN9_PART);
    Paint_SelectImage(BlackImage);
		Paint_ClearWindows(5+Font16.Width*9, 70, 5+Font16.Width*9+Font16.Width*4, 70 + Font16.Height, WHITE); //MEM USE 0
    Paint_DrawString_EN(5+Font16.Width*9, 70, use, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*14, 70, 5+Font16.Width*14+Font16.Width*4, 70 + Font16.Height, WHITE); //MEM USE 1
    Paint_DrawString_EN(5+Font16.Width*14, 70, total, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*21, 70, 5+Font16.Width*21+Font16.Width*3, 70 + Font16.Height, WHITE); //MEM USE 2
    Paint_DrawString_EN(5+Font16.Width*21, 70, use_percent, &Font16, WHITE, BLACK);
	  EPD_2IN9_Display(BlackImage);
}

void UpdateStorage(UBYTE *BlackImage,Storage * storage){
   char ssd_use[5];
	 char ssd_total[5];
	 char ssd_percent[4];
	 char disk_use[5];
	 char disk_total[5];
	 char disk_percent[4];
	 if(storage->ssd_use < 1000){
		    ssd_use[0] = ' ';
			  ssd_use[1] = storage->ssd_use / 100%10 + 0x30;
			  ssd_use[2] = storage->ssd_use / 10%10 + 0x30;
			  ssd_use[3] = storage->ssd_use %10 + 0x30;
			  ssd_use[4] = '\0';
		}
		else{
		    sprintf(ssd_use,"%d",storage->ssd_use);
		}
		
		if(storage->ssd_total < 1000){
		    //total[0] = ' ';
			  ssd_total[0] = storage->ssd_total / 100%10 + 0x30;
			  ssd_total[1] = storage->ssd_total / 10%10 + 0x30;
			  ssd_total[2] = storage->ssd_total %10 + 0x30;
			  ssd_total[3] = '\0';
		}
		else{
		    sprintf(ssd_total,"%d",storage->ssd_total);
		}
		
		if(storage->ssd_percent < 100){
		    ssd_percent[0] = ' ';
			  ssd_percent[1] = storage->ssd_percent / 10%10 + 0x30;
			  ssd_percent[2] = storage->ssd_percent %10 + 0x30;
		    ssd_percent[3] = '\0';
		}
		else{
		    sprintf(ssd_percent,"%d",storage->ssd_percent);
		}
		//
		if(storage->disk_use < 1000){
		    disk_use[0] = ' ';
			  disk_use[1] = storage->disk_use / 100%10 + 0x30;
			  disk_use[2] = storage->disk_use / 10%10 + 0x30;
			  disk_use[3] = storage->disk_use %10 + 0x30;
			  disk_use[4] = '\0';
		}
		else{
		    sprintf(disk_use,"%d",storage->disk_use);
		}
		
		if(storage->disk_total < 1000){
		    //total[0] = ' ';
			  disk_total[0] = storage->disk_total / 100%10 + 0x30;
			  disk_total[1] = storage->disk_total / 10%10 + 0x30;
			  disk_total[2] = storage->disk_total %10 + 0x30;
			  disk_total[3] = '\0';
		}
		else{
		    sprintf(disk_total,"%d",storage->disk_total);
		}
		
		if(storage->disk_percent < 100){
		    disk_percent[0] = ' ';
			  disk_percent[1] = storage->disk_percent / 10%10 + 0x30;
			  disk_percent[2] = storage->disk_percent %10 + 0x30;
		    disk_percent[3] = '\0';
		}
		else{
		    sprintf(disk_percent,"%d",storage->disk_percent);
		}
		
		EPD_2IN9_Init(EPD_2IN9_PART);
    Paint_SelectImage(BlackImage);
		
		Paint_ClearWindows(5+Font16.Width*5, 90, 5+Font16.Width*5+Font16.Width*4, 90 + Font16.Height, WHITE); //SSD USE 0
    Paint_DrawString_EN(5+Font16.Width*5, 90, ssd_use, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*10, 90, 5+Font16.Width*10+Font16.Width*4, 90 + Font16.Height, WHITE); //SSD USE 1
    Paint_DrawString_EN(5+Font16.Width*10, 90, ssd_total, &Font16, WHITE, BLACK);
  	Paint_ClearWindows(5+Font16.Width*17, 90, 5+Font16.Width*17+Font16.Width*3, 90 + Font16.Height, WHITE); //SSD USE 2
    Paint_DrawString_EN(5+Font16.Width*17, 90, ssd_percent, &Font16, WHITE, BLACK);
	
	  Paint_ClearWindows(5+Font16.Width*6, 105, 5+Font16.Width*6+Font16.Width*4, 105 + Font16.Height, WHITE); //Disk USE 0
    Paint_DrawString_EN(5+Font16.Width*6, 105, disk_use, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*11, 105, 5+Font16.Width*11+Font16.Width*4, 105 + Font16.Height, WHITE); //Disk USE 1
    Paint_DrawString_EN(5+Font16.Width*11, 105, disk_total, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*18, 105, 5+Font16.Width*18+Font16.Width*3, 105 + Font16.Height, WHITE); //Disk USE 2
    Paint_DrawString_EN(5+Font16.Width*18, 105, disk_percent, &Font16, WHITE, BLACK);
    EPD_2IN9_Display(BlackImage);
		
}


void UpdateAllmsg(UBYTE * BlackImage, CpuInfo *cpuinfo, MemInfo * meminfo, Storage *storage){
  char temp[3] = {' ',' ',' '};
	char use[3] = {' ',' ',' '};
		EPD_2IN9_Init(EPD_2IN9_PART);
    Paint_SelectImage(BlackImage);
	if(cpuinfo->temp < 100){
		   temp[1] = cpuinfo->temp/10 + 0x30;
		   temp[2] = cpuinfo->temp%10 + 0x30;
	}
	else{
	     sprintf(temp,"%d",cpuinfo->temp);
	}
	if(cpuinfo->use < 100){
	    use[1] = cpuinfo->use/10 + 0x30;
		  use[2] = cpuinfo->use%10 + 0x30;
	}
	else{
		sprintf(use,"%d",cpuinfo->use);
	}
	Paint_ClearWindows(5+Font16.Width*10, 50, 5+Font16.Width*10+Font16.Width*3, 50 + Font16.Height, WHITE); //cputemp
  Paint_DrawString_EN(5+Font16.Width*10, 50, temp, &Font16, WHITE, BLACK);
	
	Paint_ClearWindows(190+Font16.Width*4, 50, 190+Font16.Width*4+Font16.Width*3, 50 + Font16.Height, WHITE); //CPU USE
  Paint_DrawString_EN(190+Font16.Width*4, 50, use, &Font16, WHITE, BLACK);
	
	  char memuse[5];
	  char total[5];
	  char use_percent[4];
	  if(meminfo->total < 1000){
		    //total[0] = ' ';
			  total[0] = meminfo->total / 100%10 + 0x30;
			  total[1] = meminfo->total / 10%10 + 0x30;
			  total[2] = meminfo->total %10 + 0x30;
			  total[3] = '\0';
		}
		else{
		    sprintf(total,"%d",meminfo->total);
		}
		if(meminfo->use < 1000){
		    memuse[0] = ' ';
			  memuse[1] = meminfo->use / 100%10 + 0x30;
			  memuse[2] = meminfo->use / 10%10 + 0x30;
			  memuse[3] = meminfo->use %10 + 0x30;
			  memuse[4] = '\0';
		}
		else{
		    sprintf(memuse,"%d",meminfo->use);
		}
		
		if(meminfo->use_percent < 100){
		    use_percent[0] = ' ';
			  use_percent[1] = meminfo->use_percent / 10%10 + 0x30;
			  use_percent[2] = meminfo->use_percent %10 + 0x30;
		    use_percent[3] = '\0';
		}
		else{
		    sprintf(use_percent,"%d",meminfo->use_percent);
		}
		Paint_ClearWindows(5+Font16.Width*9, 70, 5+Font16.Width*9+Font16.Width*4, 70 + Font16.Height, WHITE); //MEM USE 0
    Paint_DrawString_EN(5+Font16.Width*9, 70, memuse, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*14, 70, 5+Font16.Width*14+Font16.Width*4, 70 + Font16.Height, WHITE); //MEM USE 1
    Paint_DrawString_EN(5+Font16.Width*14, 70, total, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*21, 70, 5+Font16.Width*21+Font16.Width*3, 70 + Font16.Height, WHITE); //MEM USE 2
    Paint_DrawString_EN(5+Font16.Width*21, 70, use_percent, &Font16, WHITE, BLACK);
	
	
		char ssd_use[5];
	 char ssd_total[5];
	 char ssd_percent[4];
	 char disk_use[5];
	 char disk_total[5];
	 char disk_percent[4];
	 if(storage->ssd_use < 1000){
		    ssd_use[0] = ' ';
			  ssd_use[1] = storage->ssd_use / 100%10 + 0x30;
			  ssd_use[2] = storage->ssd_use / 10%10 + 0x30;
			  ssd_use[3] = storage->ssd_use %10 + 0x30;
			  ssd_use[4] = '\0';
		}
		else{
		    sprintf(ssd_use,"%d",storage->ssd_use);
		}
		
		if(storage->ssd_total < 1000){
		    //total[0] = ' ';
			  ssd_total[0] = storage->ssd_total / 100%10 + 0x30;
			  ssd_total[1] = storage->ssd_total / 10%10 + 0x30;
			  ssd_total[2] = storage->ssd_total %10 + 0x30;
			  ssd_total[3] = '\0';
		}
		else{
		    sprintf(ssd_total,"%d",storage->ssd_total);
		}
		
		if(storage->ssd_percent < 100){
		    ssd_percent[0] = ' ';
			  ssd_percent[1] = storage->ssd_percent / 10%10 + 0x30;
			  ssd_percent[2] = storage->ssd_percent %10 + 0x30;
		    ssd_percent[3] = '\0';
		}
		else{
		    sprintf(ssd_percent,"%d",storage->ssd_percent);
		}
		//
		if(storage->disk_use < 1000){
		    disk_use[0] = ' ';
			  disk_use[1] = storage->disk_use / 100%10 + 0x30;
			  disk_use[2] = storage->disk_use / 10%10 + 0x30;
			  disk_use[3] = storage->disk_use %10 + 0x30;
			  disk_use[4] = '\0';
		}
		else{
		    sprintf(disk_use,"%d",storage->disk_use);
		}
		
		if(storage->disk_total < 1000){
		    //total[0] = ' ';
			  disk_total[0] = storage->disk_total / 100%10 + 0x30;
			  disk_total[1] = storage->disk_total / 10%10 + 0x30;
			  disk_total[2] = storage->disk_total %10 + 0x30;
			  disk_total[3] = '\0';
		}
		else{
		    sprintf(disk_total,"%d",storage->disk_total);
		}
		
		if(storage->disk_percent < 100){
		    disk_percent[0] = ' ';
			  disk_percent[1] = storage->disk_percent / 10%10 + 0x30;
			  disk_percent[2] = storage->disk_percent %10 + 0x30;
		    disk_percent[3] = '\0';
		}
		else{
		    sprintf(disk_percent,"%d",storage->disk_percent);
		}
		
		
		Paint_ClearWindows(5+Font16.Width*5, 90, 5+Font16.Width*5+Font16.Width*4, 90 + Font16.Height, WHITE); //SSD USE 0
    Paint_DrawString_EN(5+Font16.Width*5, 90, ssd_use, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*10, 90, 5+Font16.Width*10+Font16.Width*4, 90 + Font16.Height, WHITE); //SSD USE 1
    Paint_DrawString_EN(5+Font16.Width*10, 90, ssd_total, &Font16, WHITE, BLACK);
  	Paint_ClearWindows(5+Font16.Width*17, 90, 5+Font16.Width*17+Font16.Width*3, 90 + Font16.Height, WHITE); //SSD USE 2
    Paint_DrawString_EN(5+Font16.Width*17, 90, ssd_percent, &Font16, WHITE, BLACK);
	
	  Paint_ClearWindows(5+Font16.Width*6, 105, 5+Font16.Width*6+Font16.Width*4, 105 + Font16.Height, WHITE); //Disk USE 0
    Paint_DrawString_EN(5+Font16.Width*6, 105, disk_use, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*11, 105, 5+Font16.Width*11+Font16.Width*4, 105 + Font16.Height, WHITE); //Disk USE 1
    Paint_DrawString_EN(5+Font16.Width*11, 105, disk_total, &Font16, WHITE, BLACK);
	  Paint_ClearWindows(5+Font16.Width*18, 105, 5+Font16.Width*18+Font16.Width*3, 105 + Font16.Height, WHITE); //Disk USE 2
    Paint_DrawString_EN(5+Font16.Width*18, 105, disk_percent, &Font16, WHITE, BLACK);
    EPD_2IN9_Display(BlackImage);
  return;
}

